﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace ProgramMain.NetVis
{
    public enum BodyType { Cross, CableBox, Cable, TranzitBox }

    public class BodyRange : RangeBase
    {
        public BodyRange(Layers.VisLayer vis)
            : base(vis)
        { }
        public const int BaseHeight = 26;
        public override Size VirtualSize()
        {
            int weight = FibreCount * (FibreRange.BaseWidth + FibreRange.Step) < MinWeight()
                               ? MinWeight()
                               : FibreCount * (FibreRange.BaseWidth + FibreRange.Step);
            return new Size(weight, BaseHeight);
        }

       public int shift
        { get { return (int)(20 * Vis.Scale); } }

        public int cableShift
        {
            get
            {
                return shift + 220;
            }
        }

        public int CurveElementID { get; set; }

       public int FibreCount { get; set; }

       public string Caption { get; set; }
        public BodyType bodyType;

        public CrossBoxVis Equip { get; set; }
      
        private int _fontSize
        { get { return (Vis.ZoomCcale - 10) / 2 + 7; } }

        public int MinWeight()
        {
            Font font = new Font("Arial", _fontSize, FontStyle.Regular);
            return Caption.Length * (int)(font.GetHeight() / 1.5 / Vis.Scale);
        }

        public override void CalcCoordinate(Point vPoint)
        {
            VirtualPoint = vPoint;
        }

        public override void Draw(System.Drawing.Graphics layer)
        {
            if(!Visible) return;
            Font font = new Font("Arial", _fontSize, FontStyle.Regular);
            Brush brush = Brushes.Black;
           base.Draw(layer);
            if (!string.IsNullOrEmpty(Caption) && _fontSize > 5)
            {
                layer.DrawString(Caption, font, brush, this.Location + new Size(0, 0));
            }

        }

        public override bool Shift(Size sizeShift)
        {
            if (Equip == null) return false;
            Equip.ShiftVirtualPoint(sizeShift);
            return true;
        }
    }
}
